package com.example.lock.公平锁;

import java.util.concurrent.locks.ReentrantLock;

public class TestFairLock {

    public static void main(String[] args) {
        fairLock();
    }

    //公平锁
    public static void fairLock(){
        Sales sales = new Sales();
        for(int i = 0;i<10;i++){
            new Thread(sales,i+"").start();
        }
    }
}

class Sales implements Runnable{
    ReentrantLock lock = new ReentrantLock(true);
    @Override
    public void run() {
        lock.lock();
        System.out.println("线程"+Thread.currentThread().getName()+"获的时间片开始执行");
        lock.unlock();
    }
}
